/**
 * @(#) StringUtils.java
 *
 * @author lihg
 * @version V1.0 2013-10-7
 *
 * Copyright (C) 2010,2013 , Lihg
 */

/**
 * 
 */
package cn.com.dshome.acquisition.utils;

import java.io.UnsupportedEncodingException;

/**
 * 
 * Purpose:String工具类
 * 
 * @author lihg
 * @see
 * @since
 */
public abstract class StringUtils {



	/**
	 * 将Byte数组转为字符串
	 * @param content
	 * @param charSet
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String byteArray2String(byte[] content,String...charSet) throws UnsupportedEncodingException{
		if(hasLength(charSet)){
			return new String(content,charSet[0]) ;
		}else{
			return new String(content) ;
		}
	}

	/**
	 * Check that the given Object Array  is neither <code>null</code> nor of length 0.
	 * Note: Will return <code>true</code> for a Object Array if it is not null and length greater than 0
	 * <p><pre>
	 * StringUtils.hasLength(null) = false
	 * StringUtils.hasLength(new Object[]{}) = false
	 * StringUtils.hasLength(new Object[]{""}) = true
	 * StringUtils.hasLength(new Object[]{1}) = true
	 * </pre>
	 * @param objects the Object Array to check(may be <code> null </code>)
	 * @return <code>true</code> if the Object Array is not null and it's length > 0
	 */
	public static boolean hasLength(Object[] objects){
		return null!=objects && objects.length >= 0 ;
	}


	/**
	 * Check that the given CharSequence is neither <code>null</code> nor of length 0.
	 * Note: Will return <code>true</code> for a CharSequence that purely consists of whitespace.
	 * <p><pre>
	 * StringUtils.hasLength(null) = false
	 * StringUtils.hasLength("") = false
	 * StringUtils.hasLength(" ") = true
	 * StringUtils.hasLength("Hello") = true
	 * </pre>
	 * @param str the CharSequence to check (may be <code>null</code>)
	 * @return <code>true</code> if the CharSequence is not null and has length
	 * @see #hasText(String)
	 */
	public static boolean hasLength(CharSequence str) {
		return str != null && str.length() > 0;
	}

	/**
	 * Check that the given String is neither <code>null</code> nor of length 0.
	 * Note: Will return <code>true</code> for a String that purely consists of whitespace.
	 * @param str the String to check (may be <code>null</code>)
	 * @return <code>true</code> if the String is not null and has length
	 * @see #hasLength(CharSequence)
	 */
	public static boolean hasLength(String str) {
		return hasLength((CharSequence) str);
	}
}


/**
 * Revision history
 * -------------------------------------------------------------------------
 * 
 * Date Author Note
 * -------------------------------------------------------------------------
 * 2013-10-7 上午08:13:54 lihg 创建版本
 */